<?php

namespace App\Http\Controllers;

use App\Link;
use App\Question;
use App\User;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class IndexController extends Controller
{
    //
    public function index()
    {
        $questions = Question::orderBy('created_at', 'desc')->where('is_top', 0)->paginate(5);
        $topQuestion = Question::where('is_top', 1)->take(3)->orderBy('created_at', 'desc')->get();
        $wenxinQuestion = Question::where('wenxin', 1)->take(15)->orderBy('created_at', 'desc')->get();
        $users = User::orderBy('answer_num', 'desc')->get();
        $hotQuestions = Question::where('created_at', '>', Carbon::now()->modify('-7 days'))->take(15)->withCount('answers')->orderBy('created_at', 'desc')->get();
        $links = Link::all();
        $theuser = User::where('id', \Auth::id())->first();
        return view("index.index", compact('questions', 'topQuestion', 'wenxinQuestion', 'users', 'hotQuestions', 'links', 'theuser'));
    }
}
